package com.jsp.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;






import com.jsp.bean.DriverBean;
import com.jsp.util.DBUtil;

public class DriverDao {
	
	public  DriverBean insert(DriverBean driver) throws SQLException {
		Connection con=DBUtil.getConnection();
		String sql="insert into driverinformation"
				+ "(name_dr,age_dr,tel_dr,address_dr,idcard_dr,state_dr)"
				+ "values (?,?,?,?,?,?)";
		PreparedStatement state =con.prepareStatement(sql);
		state.setString(1, driver.getName_dr());
		state.setString(2, driver.getAge_dr());
		state.setString(3, driver.getTel_dr());
		state.setString(4, driver.getAddress_dr());
		state.setString(5, driver.getIdcard_dr());
		state.setString(6, driver.getState_dr());
		state.executeUpdate();
		state.close();
		con.close();
		return driver;
		
	}
	public DriverBean delete(DriverBean driver) throws SQLException {
		Connection con=DBUtil.getConnection();
		String sql="delete from driverinformation where id=?";
		PreparedStatement state =con.prepareStatement(sql);
		state.setString(1, driver.getId());
		state.executeUpdate();
		state.close();
		con.close();
		return driver;
		
	}
	public DriverBean update(DriverBean driver) throws SQLException {
		Connection con=DBUtil.getConnection();
		String sql="update driverinformation set "
				+ "id=?,name_dr=?,age_dr=?,tel_dr=?,"
				+ "address_dr=?,idcard_dr=?,state_dr=? where id=?";
		PreparedStatement state =con.prepareStatement(sql);
		state.setString(1, driver.getId());
		state.setString(2, driver.getName_dr());
		state.setString(3, driver.getAge_dr());
		state.setString(4, driver.getTel_dr());
		state.setString(5, driver.getAddress_dr());
		state.setString(6, driver.getIdcard_dr());
		state.setString(7, driver.getState_dr());
		state.setString(8, driver.getId());
		state.executeUpdate();
		state.close();
		con.close();
		return driver;
	}
}
